<?php
/**
 * @author GhostWei
 * @date Aug 21, 2012
 */
class system_user_controller_ajax extends system_user_controller_panel {

	protected $_data = null;
	public function init() {
		if(!parent::init(array('ajax' => true))) {
			return false;
		}
		$this->_data = new stdClass();
		$this->layout()->disableLayout();
		return true;
	}	

	protected function _output($msg = null, $status = true) {
		$this->_data->status = $status;
		if($msg !== null) {
			$this->_data->message = $msg;
		} elseif(!empty($this->_addMessage)) {
			$this->_data->message .= '<p>' . implode('</p><p>', $this->_addMessage) . '</p>';
		}
		$this->getResponse()->setHeader("Content-type", "application/json; charset=utf-8"); // application/json very important for IE.
		$this->getResponse()->setHeader("Last-Modified", gmdate("D, d M Y H:i:s") . " GMT");
		$this->getResponse()->setHeader("Cache-Control", "no-cache, must-revalidate");
		exit(json_encode($this->_data));
	}
	
	protected function _error($msg) {
		$this->_output($msg, false);
	}
	
	protected $_addMessage = array();
	protected function addMessage($msg) {
		$this->_addMessage[] = $msg;
	}
	
}
